package com.nulldev.util.web.HttpServer3.testing;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.web.HttpServer3.HttpServer3;
import com.nulldev.util.web.HttpServer3.SSLBehaviour;
import com.nulldev.util.web.HttpServer3.extensions.websocket.Peer;
import com.nulldev.util.web.HttpServer3.extensions.websocket.WebSocketPage;

public class WebSocketTests {

	public static void main(String[] args) throws Exception {
		final HttpServer3 hs3 = new HttpServer3(9091, true, SSLBehaviour.DISABLED, null);
		hs3.isTimingDebugEnabled = true;
		hs3.logger().debugEnabled.set(true);
		hs3.logger().traceEnabled.set(true);
		hs3.flags().enable_ws = true;
		hs3.addPage(new WebSocketPage("/") {

			@Override
			public void onTextMessage(Peer peer, String message) {
				JVM.println("Text Message: " + peer + ", message: " + message);
			}

			@Override
			public void onBinaryMessage(Peer peer, byte[] message) {
				JVM.println("Binary Message: " + peer + ", message: " + new String(message));
			}

			@Override
			public void peerDisconnected(Peer peer) {
				JVM.println("Peer Disconnect: " + peer);
			}

			@Override
			public void peerConnected(Peer peer) {
				JVM.println("Peer Connect: " + peer);
			}
		});
	}

}
